SlideShare a Scribd company logo
Class No.37  Data Structures http://ecomputernotes.com
Recap Collision Strategies in Hashing  Linear Probing Quadratic Probing  Linked List chaining  http://ecomputernotes.com
Hashing Animation Let’s see the hashing animation. We will see linear probing, quadratic probing and link list chaining in it. This is an example of how do we solve collision. We have an array shown in four different columns. The size of the array is 100 and the index is from 0 to 99. Each element of the array has two locations so we can store 200 elements in it. When we have first collision the program will use the 2nd part of the array location. When there is a 2nd collision the data is stored using the linear probing. At the top right corner we have hash function x and its definition is “mod 100”. That is when a number is passed to it, it will take mod with 100 and return the result which is used as index of the array.  In this example we are using numbers only and not dealing with the characters. We also have a statistical table on the right side. This program will generate 100 random numbers and using the hash function it will store these in the array. The numbers will be stored in the array at different locations. In the bottom left we have hashing algorithms. We have chosen the linear probing. Now the program will try to solve this problem using the linear probing. Press the run button to start it. It is selecting the numbers randomly, dividing it by 100 and the remainder is the hash value which is used as array index.  Here we have number 506. It is divided by 100 and the remainder is 6. It means that this number will be stored at the sixth array location. Similarly we have a number 206, now its remainder is also 6. As location 6 is already occupied so we will store 206 at the 2nd part of the location 6. Now we have the number 806. Its remainder is also 6. As both the parts of location 6 are occupied. Using the linear probing we will store it in the next array location i.e. 7. If we have another number having the remainder as 6, we will store it at the 2nd part of location 7. If we have number 807, its remainder is 7. The location 7 is already occupied due to the linear probing. Therefore the number 807 will be stored using the linear probing in the location 8.  http://ecomputernotes.com
Hashing Animation Let’s change the collision resolution algorithm to quadratic probing. Run the animation again. Now we have array size as 75 and the array is shown in three columns. Each location of the array can store two numbers. In quadratic probing we add square of one first i.e. 1 and then the square of two and so on in case of collisions. Here we have used a different hash function. We will take the mod with 75. When the both parts of the array location is filled we will use the quadratic probing to store the next numbers. Analyze the numbers and see where the collisions have happened.  Lets see the animation using the linked list chaining. Now the hash function uses 50 to take mod with the numbers. So far pointers are not shown. When both parts of the location are filled, we will see the link list appearing. We have four numbers having remainder 0. The two numbers will be stored in the array and the next two will be stored using the link list which is attached at the 0 location.  We are not covering the hashing topic in much depth here as it is done in algorithms and analysis of algorithms domain. This domain is not part of this course. For the time being, we will see the usage of hashing. For certain situations, table ADT can be used, which internally would be using hashing.  http://ecomputernotes.com
Applications of Hashing Compilers use hash tables to keep track of declared variables (symbol table). A hash table can be used for on-line spelling checkers — if misspelling detection (rather than correction) is important, an entire dictionary can be hashed and words checked in constant time. http://ecomputernotes.com
Applications of Hashing Game playing programs use hash tables to store seen positions, thereby saving computation time if the position is encountered again. Hash functions can be used to quickly check for inequality — if two elements hash to different values they must be different. http://ecomputernotes.com
When is hashing suitable? Hash tables are very good if there is a need for many searches in a reasonably stable table. Hash tables are not so good if there are many insertions and deletions, or if table traversals are needed — in this case, AVL trees are better. Also, hashing is very slow for any operations which require the entries to be sorted e.g. Find the minimum key http://ecomputernotes.com
Sorting Integers 20 8 5 10 7 5 7 8 10 20 How to sort the integers in this array? http://ecomputernotes.com
Elementary Sorting Algorithms Selection Sort Insertion Sort Bubble Sort http://ecomputernotes.com
Selection Sort  Main idea: find the smallest element  put it in the first position find the next smallest element put it in the second position … And so on, until you get to the end of the list http://ecomputernotes.com

More Related Content

PDF
Making a frequency chart
PPT
Beier hints
PPT
Chap08
PPTX
Data structure
PPTX
Data structures Lecture 5
PPTX
Relational algebra
PPT
Types Of Join In Sql Server - Join With Example In Sql Server
PDF
Stability Analysis in Time Domain using Routh - Hurwitz Criterion
Making a frequency chart
Beier hints
Chap08
Data structure
Data structures Lecture 5
Relational algebra
Types Of Join In Sql Server - Join With Example In Sql Server
Stability Analysis in Time Domain using Routh - Hurwitz Criterion

What's hot (20)

PPTX
Using other functions
PPTX
sorting and its types
PDF
Spreadsheet lookup functions
PPTX
Double Linked List (Algorithm)
PPT
lists
PPTX
Matrices
DOC
Assignment Algo
PPTX
EXCEL PRIMER
PPTX
Alg2 lesson 4-8
PPTX
Alg2 lesson 4-8
DOCX
Python Math Concepts Book
PDF
The 4 Step Excel 2013 Functions Guide
DOCX
Ms excel formulas
PPTX
M correlation 1
PPTX
M6L5 Solving Exponentials using Logs
PPTX
February 11, 2015,
PDF
Joins in databases
DOCX
Joins in dbms and types
PPTX
Stack & Queue using Linked List in Data Structure
Using other functions
sorting and its types
Spreadsheet lookup functions
Double Linked List (Algorithm)
lists
Matrices
Assignment Algo
EXCEL PRIMER
Alg2 lesson 4-8
Alg2 lesson 4-8
Python Math Concepts Book
The 4 Step Excel 2013 Functions Guide
Ms excel formulas
M correlation 1
M6L5 Solving Exponentials using Logs
February 11, 2015,
Joins in databases
Joins in dbms and types
Stack & Queue using Linked List in Data Structure
Ad

Viewers also liked (20)

PPT
computer notes - Data Structures - 2
PPT
computer notes - Data Structures - 1
PPT
computer notes - Data Structures - 18
PPT
computer notes - Data Structures - 10
PPT
computer notes - Data Structures - 3
PPT
computer notes - Data Structures - 15
PPT
computer notes - Data Structures - 13
PPT
computer notes - Data Structures - 5
PPT
computer notes - Data Structures - 28
PPT
computer notes - Data Structures - 27
PPT
computer notes - Data Structures - 32
PPT
computer notes - Data Structures - 11
PPT
computer notes - Data Structures - 22
PPT
computer notes - Data Structures - 29
PPT
computer notes - Data Structures - 26
PPT
computer notes - Data Structures - 23
PPT
computer notes - Data Structures - 34
PPT
computer notes - Data Structures - 9
PPT
computer notes - Data Structures - 31
PPT
computer notes - Data Structures - 7
computer notes - Data Structures - 2
computer notes - Data Structures - 1
computer notes - Data Structures - 18
computer notes - Data Structures - 10
computer notes - Data Structures - 3
computer notes - Data Structures - 15
computer notes - Data Structures - 13
computer notes - Data Structures - 5
computer notes - Data Structures - 28
computer notes - Data Structures - 27
computer notes - Data Structures - 32
computer notes - Data Structures - 11
computer notes - Data Structures - 22
computer notes - Data Structures - 29
computer notes - Data Structures - 26
computer notes - Data Structures - 23
computer notes - Data Structures - 34
computer notes - Data Structures - 9
computer notes - Data Structures - 31
computer notes - Data Structures - 7
Ad

Similar to computer notes - Data Structures - 37 (20)

PPT
computer notes - Data Structures - 36
PPTX
Data Structures-Topic-Hashing, Collision
PPT
4.4 hashing02
PPTX
DS Unit 1.pptx
PPTX
hashing in data structure for engineering.pptx
PPTX
hashing in data structure for Btech .pptx
PPTX
hashing in data structure for Btech.pptx
PPTX
Hashing
PPT
Hashing PPT
PPTX
hashing1.pptx Data Structures and Algorithms
PPTX
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
PPTX
Unit viii searching and hashing
PPTX
Hashing algorithms and its uses
PPTX
Hashing And Hashing Tables
PPTX
Lec12-Hash-Tables-27122022-125641pm.pptx
PPTX
Hashing a searching technique in data structures
PPT
Hashing
PPT
Hashing in Data Structure and analysis of Algorithms
PPTX
Hashing in Data Structure and Algorithm PPT
PPTX
session 15 hashing.pptx
computer notes - Data Structures - 36
Data Structures-Topic-Hashing, Collision
4.4 hashing02
DS Unit 1.pptx
hashing in data structure for engineering.pptx
hashing in data structure for Btech .pptx
hashing in data structure for Btech.pptx
Hashing
Hashing PPT
hashing1.pptx Data Structures and Algorithms
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
Unit viii searching and hashing
Hashing algorithms and its uses
Hashing And Hashing Tables
Lec12-Hash-Tables-27122022-125641pm.pptx
Hashing a searching technique in data structures
Hashing
Hashing in Data Structure and analysis of Algorithms
Hashing in Data Structure and Algorithm PPT
session 15 hashing.pptx

More from ecomputernotes (20)

PPT
computer notes - Data Structures - 30
PPT
computer notes - Data Structures - 39
PPT
computer notes - Data Structures - 20
DOC
Computer notes - Including Constraints
DOC
Computer notes - Date time Functions
DOC
Computer notes - Subqueries
DOC
Computer notes - Other Database Objects
PPT
computer notes - Data Structures - 19
PPT
computer notes - Data Structures - 4
DOC
Computer notes - Advanced Subqueries
DOC
Computer notes - Aggregating Data Using Group Functions
PPT
computer notes - Data Structures - 16
PPT
computer notes - Data Structures - 35
DOC
Computer notes - Enhancements to the GROUP BY Clause
DOC
Computer notes - Manipulating Data
DOC
Computer notes - Writing Basic SQL SELECT Statements
PPT
computer notes - Data Structures - 14
DOC
Computer notes - Controlling User Access
DOC
Computer notes - Using SET Operator
PPT
computer notes - Data Structures - 38
computer notes - Data Structures - 30
computer notes - Data Structures - 39
computer notes - Data Structures - 20
Computer notes - Including Constraints
Computer notes - Date time Functions
Computer notes - Subqueries
Computer notes - Other Database Objects
computer notes - Data Structures - 19
computer notes - Data Structures - 4
Computer notes - Advanced Subqueries
Computer notes - Aggregating Data Using Group Functions
computer notes - Data Structures - 16
computer notes - Data Structures - 35
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Manipulating Data
Computer notes - Writing Basic SQL SELECT Statements
computer notes - Data Structures - 14
Computer notes - Controlling User Access
Computer notes - Using SET Operator
computer notes - Data Structures - 38

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Tartificialntelligence_presentation.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
1. Introduction to Computer Programming.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Assigned Numbers - 2025 - Bluetooth® Document
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
Tartificialntelligence_presentation.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
MYSQL Presentation for SQL database connectivity
SOPHOS-XG Firewall Administrator PPT.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
1. Introduction to Computer Programming.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Advanced methodologies resolving dimensionality complications for autism neur...
Digital-Transformation-Roadmap-for-Companies.pptx
20250228 LYD VKU AI Blended-Learning.pptx
A Presentation on Artificial Intelligence
Mobile App Security Testing_ A Comprehensive Guide.pdf
Group 1 Presentation -Planning and Decision Making .pptx

computer notes - Data Structures - 37

  • 1. Class No.37 Data Structures http://ecomputernotes.com
  • 2. Recap Collision Strategies in Hashing Linear Probing Quadratic Probing Linked List chaining http://ecomputernotes.com
  • 3. Hashing Animation Let’s see the hashing animation. We will see linear probing, quadratic probing and link list chaining in it. This is an example of how do we solve collision. We have an array shown in four different columns. The size of the array is 100 and the index is from 0 to 99. Each element of the array has two locations so we can store 200 elements in it. When we have first collision the program will use the 2nd part of the array location. When there is a 2nd collision the data is stored using the linear probing. At the top right corner we have hash function x and its definition is “mod 100”. That is when a number is passed to it, it will take mod with 100 and return the result which is used as index of the array. In this example we are using numbers only and not dealing with the characters. We also have a statistical table on the right side. This program will generate 100 random numbers and using the hash function it will store these in the array. The numbers will be stored in the array at different locations. In the bottom left we have hashing algorithms. We have chosen the linear probing. Now the program will try to solve this problem using the linear probing. Press the run button to start it. It is selecting the numbers randomly, dividing it by 100 and the remainder is the hash value which is used as array index. Here we have number 506. It is divided by 100 and the remainder is 6. It means that this number will be stored at the sixth array location. Similarly we have a number 206, now its remainder is also 6. As location 6 is already occupied so we will store 206 at the 2nd part of the location 6. Now we have the number 806. Its remainder is also 6. As both the parts of location 6 are occupied. Using the linear probing we will store it in the next array location i.e. 7. If we have another number having the remainder as 6, we will store it at the 2nd part of location 7. If we have number 807, its remainder is 7. The location 7 is already occupied due to the linear probing. Therefore the number 807 will be stored using the linear probing in the location 8. http://ecomputernotes.com
  • 4. Hashing Animation Let’s change the collision resolution algorithm to quadratic probing. Run the animation again. Now we have array size as 75 and the array is shown in three columns. Each location of the array can store two numbers. In quadratic probing we add square of one first i.e. 1 and then the square of two and so on in case of collisions. Here we have used a different hash function. We will take the mod with 75. When the both parts of the array location is filled we will use the quadratic probing to store the next numbers. Analyze the numbers and see where the collisions have happened. Lets see the animation using the linked list chaining. Now the hash function uses 50 to take mod with the numbers. So far pointers are not shown. When both parts of the location are filled, we will see the link list appearing. We have four numbers having remainder 0. The two numbers will be stored in the array and the next two will be stored using the link list which is attached at the 0 location. We are not covering the hashing topic in much depth here as it is done in algorithms and analysis of algorithms domain. This domain is not part of this course. For the time being, we will see the usage of hashing. For certain situations, table ADT can be used, which internally would be using hashing. http://ecomputernotes.com
  • 5. Applications of Hashing Compilers use hash tables to keep track of declared variables (symbol table). A hash table can be used for on-line spelling checkers — if misspelling detection (rather than correction) is important, an entire dictionary can be hashed and words checked in constant time. http://ecomputernotes.com
  • 6. Applications of Hashing Game playing programs use hash tables to store seen positions, thereby saving computation time if the position is encountered again. Hash functions can be used to quickly check for inequality — if two elements hash to different values they must be different. http://ecomputernotes.com
  • 7. When is hashing suitable? Hash tables are very good if there is a need for many searches in a reasonably stable table. Hash tables are not so good if there are many insertions and deletions, or if table traversals are needed — in this case, AVL trees are better. Also, hashing is very slow for any operations which require the entries to be sorted e.g. Find the minimum key http://ecomputernotes.com
  • 8. Sorting Integers 20 8 5 10 7 5 7 8 10 20 How to sort the integers in this array? http://ecomputernotes.com
  • 9. Elementary Sorting Algorithms Selection Sort Insertion Sort Bubble Sort http://ecomputernotes.com
  • 10. Selection Sort Main idea: find the smallest element put it in the first position find the next smallest element put it in the second position … And so on, until you get to the end of the list http://ecomputernotes.com

Editor's Notes

  • #6: Start of lecture 43 after animation.
  • #11: End of lecture 43. Start of 44